<?function getCurrentEvents() {
	global $eventString, $dbname, $db, $db_selected, $pre;	
	// First, let's remove any outdated events from the webiste.	$today = date('Y-m-d');	$sql = "UPDATE casa_events SET Active = 0			WHERE			DateStart < '$today' AND			DateEnd   < '$today'";	$result = mysql_db_query($dbname,$sql);
	$eventString = '';	$sql = "SELECT * from casa_categories WHERE CatType = 'C' ORDER BY CatName";	$result = mysql_db_query($dbname,$sql);
	while ($value = mysql_fetch_assoc($result)) {		$catID   = $value[CID];		$catName = stripslashes($value[CatName]);
		$sql2 = "SELECT * from casa_events WHERE ECat = '$catID' ORDER BY DateStart DESC"; 		$result2 = mysql_db_query($dbname,$sql2);		$rows2 = mysql_num_rows($result2);
		if ($rows2>0) { $eventString .= '<h3>'.$catName.'</h3>'; }		$i=1;		while ($value2 = mysql_fetch_assoc($result2)) {			if (($i % 2) > 0) { $class = 'noRowClass'; }			else { $class = "altRow"; }			$eID       = $value2[EID];			$eTitle    = stripslashes($value2[EventTitle]);			$eLocation = stripslashes($value2[EventLocation]);			$eDesc     = stripslashes($value2[EventDesc]);			$eURL      = $value2[EventURL];			$eRegURL   = $value2[EventRegURL];			$dateTimeStart = convertDateTime($value2[DateStart]);			$dateTimeEnd   = convertDateTime($value2[DateEnd]);			$eTimes    = $value2[EventTimes];			$eReg      = $value2[Registration];			$active    = $value2[Active];
			$dateStart = $dateTimeStart[0];			$dateEnd   = $dateTimeEnd[0];
			// Check for any registrations for this event			$sqlR = "SELECT COUNT(UID) AS RegCount from casa_event_registration WHERE EID = '$eID'";			$resultR = mysql_db_query($dbname,$sqlR);			$regCount = mysql_fetch_assoc($resultR);			$regCount = $regCount[RegCount];		
			$eventString .= '<div class="'.$class.'" id="row'.$eID.'" onMouseOver="rowHoverControls('.$eID.',\'on\');" onMouseOut="rowHoverControls('.$eID.',\'off\',\''.$class.'\')">';			$eventString .= '<div style="padding: 3px; text-align: center; vertical-align: top; width: 50px; float: left;">';				$eventString .= '<div style="display: none;" id="control'.$eID.'">';				$eventString .= '<a href="#" onClick="editEvent('.$eID.'); return false;"><img src="images/buttonEditBig.gif" id="editButton'.$eID.'" style="border: none;" alt="Edit" /></a>';				$eventString .= '&nbsp;<a href="#" onClick="confirmDelete(\''.$eID.'\',\'event\'); return false;"><img src="images/buttonDeleteBig.gif" style="border: none;" alt="Delete" /></a>';				$eventString .= '</div>';			$eventString .= '</div><div style="width: 90%; float: left; padding: 3px;">';
			$eventString .= '<h4>'.$eTitle.'</h4>';			$eventString .= '<p><b>Dates:</b> '.$dateStart;			if (!empty($dateEnd)) {				$eventString .= ' to '.$dateEnd;			}			$eventString .= '</p>';			if (!empty($eTimes)) {				$eventString .= '<p><b>Times:</b> '.$eTimes.'</p>';			}
			// Check for active			$eventString .= '<div id="onHomeDiv'.$eID.'" style="margin-left: 5px;">';			if ($active == 1) {				$eventString .= '<img src="images/iconCheckGreenOn.gif" onClick="swapActive('.$eID.'); return false;" style="cursor: pointer;" alt="Click to deactivate event" /> Active Event';			} else {				$eventString .= '<img src="images/iconCheckGreenOff.gif" onClick="swapActive('.$eID.'); return false;" style="cursor: pointer;" alt="Click to activate event" /> <span style="color: #ccc;">Not Active</span>';			}			$eventString .= '</div>';
			if (!empty($eLocation)) {				$eventString .= '<p class="sectionLocation">'.$eLocation.'</p>';			}			if (!empty($eURL)) {				$eventString .= '<p class="sectionWebsite"><a href="'.$eURL.'" target="_blank">Event website</a></p>';			}			if (!empty($eRegURL)) {				$eventString .= '<p class="sectionWebsite"><a href="'.$eRegURL.'" target="_blank">Event registration link</a></p>';			}						if (!empty($eDesc)) {				$eventString .= '<p>'.$eDesc.'</p>';			}			if ($regCount>0) {				$eventString .= '<div style="float: right;" class="regButton" onclick="showRegistered('.$eID.'); return false;" title="View registrations">'.$regCount.' Registered</div>';				$eventString .= '<div id="buttonResend" style="float: right; margin-right: 10px;" class="sendButton" onclick="resendInfo('.$eID.'); return false;" title="Resend event information"></div>';
				$eventString .= '<div style="clear: right;"></div>';
			}			$eventString .= '</div><div style="clear: left; height: 10px;"></div></div>';
			$i++;		}		$eventString .= '<div style="height: 20px;"></div>';	}	return $eventString;}
function getNewsCategories($display=null) {	global $catString, $dbname, $db, $db_selected, $pre;		$catString = '';	// Get news and announcements	$sql = "SELECT * from ncdb_MainCat WHERE SiteArea = 'N' ORDER BY DisplayOrder";	$result = mysql_db_query($dbname,$sql);		while ($value = mysql_fetch_assoc($result)) {		$catID   = $value[CatID];		$catName = stripslashes($value[CatTitle]);			if ($display == 'select') {			$catString .= '<option value="'.$catID.'">'.$catName.'</option>';		}	}	return $catString;}
function saveEvent($phpString,$action=null) {	global $catString, $dbname, $db, $db_selected, $pre;	$userid = $_SESSION[UID];		// Parse phpString	$eArray = explode('|',$phpString);		$eCat       = $eArray[0];	$eTitle     = fieldToDB($eArray[1]);	$eDesc      = $eArray[2];	$eLocation  = fieldToDB($eArray[3]);	$eURL       = $eArray[4];	$eDateStart = extDateToMySQL($eArray[5]);	$eDateEnd   = extDateToMySQL($eArray[6]);	$eTimes     = fieldToDB($eArray[7]);	$eFile      = $eArray[8];	$eReg       = $eArray[9];	$eRegURL    = $eArray[10];	$eID        = $eArray[11];		if ($eURL == 'http://') {		$eURL = '';	}
	if ($eRegURL == 'http://') {		$eRegURL = '';	}			if ($action == 'add') {			$sql = "INSERT into casa_events (				ECat,				Userid,				EventTitle,				EventLocation,				EventDesc,				EventURL,				EventRegURL,				DateStart,				DateEnd,				EventTimes,				Registration,				Active				) values (				'$eCat',				'$userid',				'$eTitle',				'$eLocation',				'$eDesc',				'$eURL',				'$eRegURL',				'$eDateStart',				'$eDateEnd',				'$eTimes',				'$eReg',				'1'				)";	} elseif ($action == 'edit') {		$sql = "UPDATE casa_events SET				ECat          = '$eCat',				EventTitle    = '$eTitle',				EventLocation = '$eLocation',				EventDesc     = '$eDesc',				EventURL      = '$eURL',				EventRegURL   = '$eRegURL',				DateStart     = '$eDateStart',				DateEnd       = '$eDateEnd',				EventTimes    = '$eTimes',				Registration  = '$eReg'				WHERE EID = '$eID'";	}				$result = mysql_db_query($dbname,$sql);}function deleteEvent($eID) {	global $dbname, $db, $db_selected, $pre;		$sql = "DELETE from casa_events WHERE EID = '$eID'";	$result = mysql_db_query($dbname,$sql);}
function getEventForEdit($eID) {	global $editString, $dbname, $db, $db_selected, $pre;		$sql = "SELECT * from casa_events WHERE EID = '$eID'";	$result = mysql_db_query($dbname,$sql);	$row = mysql_fetch_assoc($result);		$eCat       = $row[ECat];	$eTitle     = DBToField($row[EventTitle]);	$eLocation  = DBToField($row[EventLocation]);	$eDesc      = stripslashes($row[EventDesc]);	$eURL       = $row[EventURL];	$eRegURL    = $row[EventRegURL];	$eTimes     = $row[EventTimes];	$eReg       = $row[Registration];			// Extract date from datetime	$eDateStartArray = explode(' ',$row[DateStart]);	$eDateEndArray   = explode(' ',$row[DateEnd]);		$eDateStart = mySQLToExt($eDateStartArray[0]);	$eDateEnd   = mySQLToExt($eDateEndArray[0]);			$editString = $eID.'|'.$eCat.'|'.$eTitle.'|'.$eLocation.'|'.$eDesc.'|'.$eURL.'|'.$eRegURL.'|'.$eDateStart.'|'.$eDateEnd.'|'.$eTimes.'|'.$eReg;	return $editString;}
function swapOnHome($eID) {	global $returnString, $dbname, $db, $db_selected, $pre;		$sql = "SELECT DisplayOnHome from ncdb_Events WHERE EID = '$eID'";	$result = mysql_db_query($dbname,$sql);	$row = mysql_fetch_assoc($result);	$onHome = $row[DisplayOnHome];		if ($onHome == 1) {		$newOnHome = 0;		$returnString = '<img src="images/iconCheckGreenOff.gif" onClick="swapOnHome('.$eID.'); return false;" style="cursor: pointer;" alt="Click to display on home page" /> <span style="color: #ccc;">On Home Page</span>';		} else {		$newOnHome = 1;		$returnString = '<img src="images/iconCheckGreenOn.gif" onClick="swapOnHome('.$eID.'); return false;" style="cursor: pointer;" alt="Click to displayu on home page" /> On Home Page';		}		$sqlUpdate = "UPDATE ncdb_Events SET DisplayOnHome = '$newOnHome' WHERE EID = '$eID'";	$result = mysql_db_query($dbname,$sqlUpdate);		return $eID.'|'.$returnString;}function swapActive($eID) {	global $returnString, $dbname, $db, $db_selected, $pre;		$sql = "SELECT Active from casa_events WHERE EID = '$eID'";	$result = mysql_db_query($dbname,$sql);	$row = mysql_fetch_assoc($result);	$active = $row[Active];		if ($active == 1) {		$newActive = 0;		$returnString = '<img src="images/iconCheckGreenOff.gif" onClick="swapActive('.$eID.'); return false;" style="cursor: pointer;" alt="Click to activate event" /> <span style="color: #ccc;">Not Active</span>';		} else {		$newActive = 1;		$returnString = '<img src="images/iconCheckGreenOn.gif" onClick="swapActive('.$eID.'); return false;" style="cursor: pointer;" alt="Click to deactivate event" /> Active Event';		}		$sqlUpdate = "UPDATE casa_events SET Active = '$newActive' WHERE EID = '$eID'";	$result = mysql_db_query($dbname,$sqlUpdate);		return $eID.'|'.$returnString;}
function getRegistered($eID) {	global $returnString, $dbname, $db, $db_selected, $pre;		$sql = "SELECT C.CatName,P.ProgramName,U.UID,U.ProgramID,U.NameFirst,U.NameLast,U.Email,U.Phone1,U.PositionID			FROM casa_event_registration ER 			LEFT JOIN casa_users U ON ER.UID = U.UID			LEFT JOIN casa_programs P ON U.ProgramID = P.PID				LEFT JOIN casa_categories C ON C.CID = U.PositionID					LEFT JOIN casa_events E ON E.EID = '$eID' 			WHERE ER.EID = '$eID' ORDER BY ProgramName,NameLast";	$result = mysql_db_query($dbname,$sql);	$rows = mysql_num_rows($result);	
	$i=0;
	while ($value = mysql_fetch_assoc($result)) {
		if (($i % 2) > 0) { $class = 'noRowClass'; }
			else { $class = "altRow"; }
		
		$uIDArray[$i]       = $value[UID];
		$programIDArray[$i] = $value[ProgramID];
		$programArray[$i]   = stripslashes($value[ProgramName]);
		$nameFirstArray[$i] = $value[NameFirst];
		$nameLastArray[$i]  = $value[NameLast];
		$emailArray[$i]     = $value[Email];
		$phoneArray[$i]     = $value[Phone1];
		$positionArray[$i]  = $value[CatName];
		$positionIDArray[$i]= $value[PositionID];
		$i++;
	}	
	$totalRows = $i-1;
		// Get event title	$sql2 = "SELECT EventTitle from casa_events WHERE EID = '$eID'";	$result2 = mysql_db_query($dbname,$sql2);	$row = mysql_fetch_assoc($result2);	$eventTitle = stripslashes($row[EventTitle]);		$returnString  = '<h1>'.$rows.' registered for '.$eventTitle.'</h1>';	
	$returnString .= '<div id="editTable" style="display: none;">';
	$returnString .= '<table class="dataTable" style="width: 100%;">';
	for($a=0;$a<=$totalRows;$a++) {
		if (($a % 2) > 0) { $class = 'noRowClass'; }
			else { $class = "altRow"; }
			
		$uID       = $uIDArray[$a];
		$programID = $programIDArray[$a];
		$program   = stripslashes($programArray[$a]);
		$nameFirst = $nameFirstArray[$a];
		$nameLast  = $nameLastArray[$a];
		$email     = $emailArray[$a];
		$phone     = $phoneArray[$a];
		$position  = $positionArray[$a];
		$positionID = $positionIDArray[$a];	
		
		$returnString .= '<tr class="'.$class.'" id="row'.$uID.'">';
			$returnString .= '<td style="width: 15px;"><img src="../images/button_delete.gif" alt="Delete" onClick="deleteReg('.$uID.','.$eID.');" style="cursor: pointer;" /></td>';
			$returnString .= '<td><select id="program'.$uID.'" size="1" style="width: 200px;">
							<option>Program...</option>
							<option></option>';
			
			// Render positions
			$programs = getPrograms('select',$programID);
			$returnString .= $programs;
			$returnString .= '</select>
						</td>';			
			$returnString .= '<td><input type="text" id="nameFirst'.$uID.'" value="'.$nameFirst.'" style="width: 100px;" /></td>';
			$returnString .= '<td><input type="text" id="nameLast'.$uID.'" value="'.$nameLast.'" style="width: 100px;" /></td>';
			$returnString .= '<td><input type="text" id="email'.$uID.'" value="'.$email.'" style="width: 150px;" title="'.$email.'" /><input type="hidden" id="emailHidden'.$uID.'" value="'.$email.'" /></td>';
			$returnString .= '<td><input type="text" id="phone'.$uID.'" value="'.$phone.'" style="width: 120px;" title="'.$phone.'" /></td>';
			$returnString .= '<td><select id="position'.$uID.'" size="1" style="width: 100px;">
							<option>Position...</option>
							<option></option>';
			
			// Render positions
			$positions = getCategories('select','P',$positionID);
			$returnString .= $positions;
			$returnString .= '</select>
						</td>';			
			$returnString .= '<td style="width: 70px;"><img src="../images/buttonEdit.gif" alt="Edit" onClick="saveReg(\'edit\','.$uID.','.$eID.');" style="cursor: pointer;" /></td>';
		$returnString .= '</tr>';
	}
	$returnString .= '</table></div>';
	$returnString .= '</div><div id="staticTable">';
	$returnString .= '<table class="dataTable" style="width: 100%;">';
	for($a=0;$a<=$totalRows;$a++) {
		if (($a % 2) > 0) { $class = 'noRowClass'; }
			else { $class = "altRow"; }
			
		$uID       = $uIDArray[$a];
		$programID = $programIDArray[$a];
		$program   = stripslashes($programArray[$a]);
		$nameFirst = $nameFirstArray[$a];
		$nameLast  = $nameLastArray[$a];
		$email     = $emailArray[$a];
		$phone     = $phoneArray[$a];
		$position  = $positionArray[$a];
		$positionID = $positionIDArray[$a];	
		
		$returnString .= '<tr class="'.$class.'" id="row'.$uID.'">';
			$returnString .= '<td>'.$program.'</td>';			
			$returnString .= '<td>'.$nameFirst.' '.$nameLast.'</td>';
			$returnString .= '<td><a href="mailto:'.$email.'">'.$email.'</a></td>';
			$returnString .= '<td>'.$phone.'</td>';
			$returnString .= '<td>'.$position.'</td>';			
		$returnString .= '</tr>';
	}
	$returnString .= '</table>';
	$returnString .= '</div>';
		return $returnString;}function deleteReg($uID,$eID) {	global $dbname, $db, $db_selected;		$sql = "DELETE from casa_event_registration WHERE EID = '$eID' AND UID = '$uID'";	$result = mysql_db_query($dbname,$sql);
}
function saveReg($phpString,$eID,$doWhat,$regUserID=null) {	global $returnString,$dbname, $db, $db_selected;		// Parse PHP String	$valueArray = explode('|',$phpString);			$programID = $valueArray[0];	$nameFirst = fieldToDB($valueArray[1]);	$nameLast  = fieldToDB($valueArray[2]);	$phone     = fieldToDB($valueArray[3]);	$email     = fieldToDB($valueArray[4]);	$position  = fieldToDB($valueArray[5]);	$emailHidden = $valueArray[6];		if ($phone == 'Phone Number') {		$phone = '';	}	if ($email == 'Email Address') {		$email = '';	}	if ($email == '[hidden]') {		$email = $emailHidden;	}		if ($doWhat == 'add') {		// Is this person already in the user table?		$sql = "SELECT UID from casa_users WHERE NameFirst = '$nameFirst' AND NameLast = '$nameLast' AND Email = '$email'";		$result = mysql_db_query($dbname,$sql);		if (mysql_num_rows($result)<1) {			$sql = "INSERT into casa_users (					ProgramID,					NameFirst,					NameLast,					Email,					Phone1,					PositionID					) values (					'$programID',					'$nameFirst',					'$nameLast',					'$email',					'$phone',					'$position'					)";			$result = mysql_db_query($dbname,$sql);						// Get UID for this person			$uID = mysql_insert_id();					} else {					$uIDRow = mysql_fetch_assoc($result);			$uID = $uIDRow[UID];		}					// Enter record into casa_event_registration		$sql = "INSERT into casa_event_registration (					EID,					UID					) values (					'$eID',					'$uID'					)";		$result = mysql_db_query($dbname,$sql);				$string  = '<table style="width: 100%;">				<tr>					<td style="width: 50px;"><img src="images/button_delete.gif" alt="Delete" onClick="deleteReg('.$uID.');" style="cursor: pointer;" /></td>';		$string .= '<td><input type="text" id="nameFirst'.$uID.'" value="'.$nameFirst.'" style="width: 120px;" /></td>';		$string .= '<td><input type="text" id="nameLast'.$uID.'" value="'.$nameLast.'" style="width: 120px;" /></td>';		$string .= '<td><input type="text" id="email'.$uID.'" value="'.$email.'" style="width: 150px;" /></td>';		$string .= '<td><input type="text" id="phone'.$uID.'" value="'.$phone.'" style="width: 120px;" /></td>';		$string .= '<td><select id="position'.$uID.'" size="1" style="width: 100px;">						<option>Position...</option>						<option></option>';				// Render positions		$positions = getCategories('select','P',$position);		$string .= $positions;		$string .= '</select>					</td>';		$string .= '<td style="width: 80px;"><img src="images/buttonEdit.gif" alt="Edit" onClick="saveReg(\'edit\','.$uID.');" style="cursor: pointer;" /></td>				</tr>				</table>';		$returnString = $string.'|'.$uID;	} else {		// We're editing a record now				$uID = $regUserID;				$sql = "UPDATE casa_users SET				ProgramID  = '$programID',				NameFirst  = '$nameFirst',				NameLast   = '$nameLast',				Email      = '$email',				Phone1     = '$phone',				PositionID = '$position'				WHERE					UID = '$uID'";		$result = mysql_db_query($dbname,$sql);				$returnString = 'null|'.$uID;		}		return $returnString;}
function resendInfo($eID) {
	global $dbname, $db, $db_selected;
	
	// Get event details
	$sqlE = "SELECT * from casa_events WHERE EID = '$eID'";
	$resultE = mysql_db_query($dbname,$sqlE);
	$rowE = mysql_fetch_assoc($resultE);
	
	$eventTitle    = DBToField($rowE[EventTitle]);
	$eventLocation = DBToEmail($rowE[EventLocation]);  
	$eventDesc     = DBToEmail($rowE[EventDesc]);
	$eventURL      = $rowE[EventURL];
	$eventDateStartArray = convertDateTime($rowE[DateStart]);
	$eventDateEndArray   = convertDateTime($rowE[DateEnd]);
	$eventTimes    = $rowE[EventTimes];
	
	$fromName    = 'CASA3G';
	$fromAddress = 'noreply@casa3g.org';
	$subject     = 'CASA3G.ORG Event Registration';
	
	$message    = 'Thank you for registering. The event information is listed below.'.Chr(10).Chr(10);
	$message    .= '**** '.$eventTitle.' *****'.Chr(10).Chr(10);
	if (!empty($eventDesc)) {
		$message .= $eventDesc.Chr(10).Chr(10);
	}
	if (!empty($eventLocation)) {
		$message .= 'Location: '.$eventLocation.Chr(10);
	}
	if (!empty($eventDateStartArray[0])) {
		$message .= 'Date(s):  '.$eventDateStartArray[0].' '.$eventDateStartArray[1];
	}
	if (!empty($eventDateEndArray[0])) {
		$message .= ' to '.$eventDateEndArray[0].' '.$eventDateEndArray[1].Chr(10);
	}
	if (!empty($eventTimes)) {
		$message .= 'Time:     '.$eventTimes;
	}
	$message    .= Chr(10).'If you have any questions, please contact '.INFO_MAIL; 
		
	// Get all registered users for this event
	$sqlU = "SELECT U.NameFirst,U.NameLast,U.Email 
			FROM casa_users U
			LEFT JOIN casa_event_registration ER ON U.UID = ER.UID
			WHERE
			ER.EID = '$eID'";
	$resultU = mysql_db_query($dbname,$sqlU);
	$string = '';
	
	while ($valueU = mysql_fetch_assoc($resultU)) {
		$fullName = $valueU[NameFirst].' '.$valueU[NameLast];
		$email    = $valueU[Email];
		
		$string .= $fullName.' '.$email.'<br>'; 
	
		// Send message
		$to   = $email;
		$body = $fullName.','.Chr(10).$message;
	
		// Send mail to user
		if (mailNew($fromName, $fromAddress, $to, $subject, $message)) {
			$string .= 'SUCCESS!';
		} else {
			$string .= 'ERROR!';
		}
	}	
	return $string;
}

?>